<?php
	class WarehouseController extends BaseController {

        public function getList()
        {
            if(Input::has('shop_id'))
            {
                $shop_id=Input::get('shop_id');
            }
            return Resonse::json(Warehourses::Select($shop_id));
        }
		public function getSelectdata($shop_id){
			try{
	            echo json_encode(Warehourses::Select($shop_id));
	        }
	        catch(Exception $e)
	        {
	            return ErrorResponse::SendErrorMessage($e->getMessage());
	        }
	    }
	  
	    public function postRegister(){

           try{
	            $input=Input::json()->all();

	            $shop_id=InputHelper::getInput($input,'shop_id');

	            $name=InputHelper::getInput($input,'name');

	            $address=InputHelper::getInput($input,'address');

	            $comments=InputHelper::getInput($input,'comments','');

	        }
	        catch(Exception $e)
	        {
	            return ErrorResponse::SendErrorMessage($e->getMessage());
	        }

		    try{
		        if(Warehourses::Insert($name,$address,$comments,$shop_id))
	            {
	                $shop_id = Warehourses::getWareId($name);
	                if($shop_id!=-1)
	                {
	                    return Response::json(array('status'=>'success','id'=>$shop_id));
	                }
	            }  
		    }
		    catch(Exception $e)
		    {
		        return ErrorResponse::SendErrorMessage($e->getMessage());
		    }
		}
	  
	    public function postEdit(){
	     
	    	//checks the information input
	    	try{
	            $input=Input::json()->all();

	            $warehouse_id=InputHelper::getInput($input,'warehouse_id');

	            $name=InputHelper::getInput($input,'name');

	            $address=InputHelper::getInput($input,'address');

	            $comments=InputHelper::getInput($input,'comments','');

	        }
	        catch(Exception $e)
	        {
	            return ErrorResponse::SendErrorMessage($e->getMessage());
	        }
	        // edit to database 
		    try{
		    	if(Warehourses::Edit($name,$address,$comments,$warehouse_id))
	        	{
	        		return Response::json(array('status'=>'success'));
	        	}
	        }
	        catch(Exception $e)
	        {
	            return ErrorResponse::SendErrorMessage($e->getMessage());
	        }
	    }
	    public function postDeletedata(){
	    	try{
	            $input=Input::json()->all();
	            $warehouse_id=InputHelper::getInput($input,'warehouse_id');
	        }catch(Exception $e){
	        	return ErrorResponse::SendErrorMessage($e->getMessage());
	        }
	        try{
	        	if(Warehourses::deletedata($warehouse_id))
	        	{
	        		return Response::json(array('status'=>'success'));
	        	}	             
	        }
	        catch(Exception $e)
	        {
	            return ErrorResponse::SendErrorMessage($e->getMessage());
	        }
	    }

	}
?>